package com.szt.mobile.inventory.common.entity;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Keep;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.Date;
import java.util.List;

/**
 * Created by yanzhaodi on 2017/11/16.
 */
@Entity(nameInDb = "t_inventory")
public class Inventory extends BaseEntity {

    @Id
    public Long id_;

    public String id;
    // 地点
    public String strTARGET_ID;
    // 描述
    public String sDESCRIBE;
    // 日期
    public Date make_date;

    @ToMany(referencedJoinProperty = "inventoryId")
    public List<AssetsList> detail;

    // 盘点单状态， 1， 未完成， 2， 已完成， -1， 盘点中
    public Integer status = 0;

    // 是否已经下载了资产详情数据
    public Boolean hasDownDetail = false;

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1781302417)
    public synchronized void resetDetail() {
        detail = null;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Keep
    public List<AssetsList> getDetail() {
        if (detail == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            AssetsListDao targetDao = daoSession.getAssetsListDao();
            List<AssetsList> detailNew = targetDao._queryInventory_Detail(id_);
            synchronized (this) {
                if(detail == null) {
                    detail = detailNew;
                }
            }
        }
        return detail;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1763418221)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getInventoryDao() : null;
    }

    public Boolean getHasDownDetail() {
        return this.hasDownDetail;
    }

    public void setHasDownDetail(Boolean hasDownDetail) {
        this.hasDownDetail = hasDownDetail;
    }

    public Integer getStatus() {
        return this.status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getMake_date() {
        return this.make_date;
    }

    public void setMake_date(Date make_date) {
        this.make_date = make_date;
    }

    public String getSDESCRIBE() {
        return this.sDESCRIBE;
    }

    public void setSDESCRIBE(String sDESCRIBE) {
        this.sDESCRIBE = sDESCRIBE;
    }

    public String getStrTARGET_ID() {
        return this.strTARGET_ID;
    }

    public void setStrTARGET_ID(String strTARGET_ID) {
        this.strTARGET_ID = strTARGET_ID;
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Long getId_() {
        return this.id_;
    }

    public void setId_(Long id_) {
        this.id_ = id_;
    }

    /** Used for active entity operations. */
    @Generated(hash = 433391049)
    private transient InventoryDao myDao;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    @Generated(hash = 110912068)
    public Inventory(Long id_, String id, String strTARGET_ID, String sDESCRIBE, Date make_date,
            Integer status, Boolean hasDownDetail) {
        this.id_ = id_;
        this.id = id;
        this.strTARGET_ID = strTARGET_ID;
        this.sDESCRIBE = sDESCRIBE;
        this.make_date = make_date;
        this.status = status;
        this.hasDownDetail = hasDownDetail;
    }

    @Generated(hash = 375708430)
    public Inventory() {
    }



}
